package cool.taomu.toolkit.platform.utils

import java.util.Arrays
import java.util.HashMap
import java.util.List
import java.util.Map
import java.util.stream.Collectors
import javax.servlet.http.HttpServletRequest

class HttpUtils {
	def static getHeaders(HttpServletRequest request) {
		var headerMap = new HashMap<String, String>();
		var headerNames = request.getHeaderNames();
		while (headerNames.hasMoreElements()) {
			var key = headerNames.nextElement();
			var value = request.getHeader(key);
			headerMap.put(key, value);
		}
		return headerMap;
	}

	def static Map<String, List<String>> convertMap(Map<String, String[]> map) {
		map.entrySet.stream.collect(
			Collectors.toMap(
				[it.key],
				[entry|Arrays.asList(entry.value)]
			)
		)
	}
}
